#include<cstdio>
#include<cstring>
const int maxn=200010;
bool v[80];
struct node
{
	int left,right,val;
};
node tree[maxn*4];
int n,t,o;
void build(int l,int r,int u)
{
	tree[u].left=l;
	tree[u].right=r;
	tree[u].val=1;
	if(l==r)return;
	int mid=(l+r)/2;
	build(l,mid,u*2);
	build(mid+1,r,u*2+1);
}
void update(int l,int r,int val,int u)
{
	if(l<=tree[u].left&&r>=tree[u].right)
	{
		tree[u].val=val;
		return;
	}
	if(tree[u].val==val)return;
	if(tree[u].val>0)
	{
		tree[u*2].val=tree[u*2+1].val=tree[u].val;
		tree[u].val=0;
	}
	int mid=(tree[u].left+tree[u].right)/2;
	if(r<=mid)update(l,r,val,u*2);
	else if(l>mid)update(l,r,val,u*2+1);
	else 
	{
		update(l,r,val,u*2);
		update(l,r,val,u*2+1);
	}
}
int query(int l,int r,int u)
{
	int sum=0;
	if(tree[u].val>0)
	{
		if(v[tree[u].val]==false)
		{
			sum++;
			v[tree[u].val]=true;
		}
		return sum;
	}
	int mid=(tree[u].left+tree[u].right)/2;
	if(r<=mid)sum+=query(l,r,u*2);
	else if(l>mid)sum+=query(l,r,u*2+1);
	else
	{
		sum+=query(l,r,u*2);
		sum+=query(l,r,u*2+1);
	}
	return sum;
}

int main()
{
	scanf("%d%d%d",&n,&t,&o);
	build(1,n,1);
	for(int i=1;i<=o;i++)
	{
		char op;
		int a,b,c;
		scanf("%c%c",&op,&op);
		if(op=='C')
		{
			scanf("%d%d%d",&a,&b,&c);
			update(a,b,c,1);
		}
		if(op=='P')
		{
			scanf("%d%d",&a,&b);
			memset(v,0,sizeof(v));
			printf("%d\n",query(a,b,1));
		}
	}
	return 0;
}

